/**
 * Created by Webdd on 15/4/5.
 */
function writeObj(obj){
    var description = "";
    for(var i in obj){
        var property=obj[i];
        description+=i+" = "+property+"\n";
    }
    alert(description);
}


/**
 * 判断数组中是否存在某个元素
 *
 * @type {string}
 */

Array.prototype.S=String.fromCharCode(2);
Array.prototype.in_array=function(e)
{
    var r=new RegExp(this.S+e+this.S);
    return (r.test(this.S+this.join(this.S)+this.S));
}


/**
 * 对话框 URL:点击确认后跳转的地址 message:提示信息
 */
function delConfirm(URL,message){
    $.confirm({
        'title'		: '警告对话框!',
        'message'	: message,
        'buttons'	: {
            'SURE'	: {
                'class'	: 'btn-flat info',
                'action': function(){
                    $.post(URL,{},function(result){
                        var obj = eval('(' + result + ')');
                        if (obj.result == 'RESULT_OK') {
                            location.reload();
                        } else {
                            alert(obj.msg);
                        }
                    });
                }
            },
            'CANCEL'	: {
                'class'	: 'btn-flat gray',
                'action': function(){return false;}
            }
        }
    });
}

/**
 * 表单提交方法
 *
 * @param formid  表单ID
 * @param tourl   提交URL
 * @param cancleurl  返回URL
 */
function submitForm(formid,url) {
    lshow();
    $.ajax({
        // async : true,
        type: "post",
        url: url,
        dataType: "json",
        data: $("#" + formid).serialize(),
        timeout : 20000,
        success: function(data) {
            lhide();
            if (data.result == "RESULT_OK") {
                if (data.msg != '') alert(data.msg);
                window.location.href = data.data;
            } else {
                alert(data.msg);
            }
        },
        error: function(request) {
            lhide();
            alert('提交失败');
        }
    });
}